home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / autofind / source / mapper.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  5.2 KB  |  167 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. -- Filename: 
  3. --     mapper.sx
  4.  
  5. -- Other Files Required:
  6. --     mapwin.sx, mapdoc.sx
  7.  
  8. -- Purpose:  
  9. --     Class definition for the Mapper class.
  10.  
  11. -- Specialized Classes:  
  12. --     Mapper
  13.  
  14. -- Instructions to User:
  15. --     Class Mapper is a TwoDSpace which is used to display the location of objects are on a
  16. --     map. The current implementation is specific to the map in the AutoFinder title (some
  17. --     attempt has been made at generality). All objects are represented by a push pin. When
  18. --     the pin is clicked, the editObject method is invoked on self, which brings up a detail
  19. --     window with a MapDocument for that object. If the detail is already displayed, it simply
  20. --     sets the target of the document to the selected object.
  21.  
  22. -- Author:
  23. --     Steve Mayer
  24.  
  25. in module Autofinder
  26.  
  27. if (NOT isdefined detailWindow) do filein theScriptDir name:"mapwin.sx"
  28.  
  29. class Mapper (TwoDSpace)
  30. instance variables
  31.     media
  32.     detailMaps
  33.     quadrantWidth        -- Width of a quadrant on the big map.
  34.     quadrantHeight        -- Height of a quadrant on the big map.
  35.     detailWidth        -- Width of a detail map.
  36.     detailHeight        -- Height of a detail map.
  37.     detailDocument
  38.     control
  39. end
  40.  
  41. method init self {class Mapper} #rest args #key manager: media: \
  42.     quadrantWidth: (40) quadrantHeight: (40) detailWidth: (368) \
  43.     detailHeight: (276) ->
  44. (
  45.     apply nextMethod self args
  46.     self.stroke := whiteBrush
  47.     self.detailDocument := undefined
  48.     self.quadrantWidth := quadrantWidth
  49.     self.quadrantHeight := quadrantHeight
  50.     self.detailWidth := detailWidth
  51.     self.detailHeight := detailHeight
  52.     local ac := new ActuatorController space:self wholeSpace:true
  53.     local dc := new DragController space:self wholeSpace:true
  54.     self.control := #(ac, dc)
  55.     prepend self media["map"]
  56.     self.media := media
  57.     
  58.     initDetailMaps self
  59.     return self
  60. )
  61.  
  62. method leaveScene self {class Mapper} ->
  63. (
  64.     for i in self.control do
  65.         i.space := undefined
  66.     emptyout self.control
  67.  
  68.     emptyout self
  69.     for i in self.detailMaps do
  70.         makePurgeable i
  71. )
  72.  
  73. method initDetailMaps self {class Mapper} ->
  74. (
  75.     -- Detail mapping maps rectangles on the big map to detail maps.
  76.     self.detailMaps := new KeyedLinkedList
  77.     add self.detailMaps (11 * 100 + 11) self.media["Woodside"]
  78.     add self.detailMaps (4 * 100 + 10) self.media["Halfmoon Bay"]
  79.     add self.detailMaps (10 * 100 + 5) self.media["San Mateo"]
  80.     add self.detailMaps (5 * 100 + 4) self.media["Hillsborough"]
  81.     add self.detailMaps (10 * 100 + 7) self.media["Belmont"]
  82.     add self.detailMaps (11 * 100 + 7) self.media["Redwood City"]
  83. )
  84.  
  85. method getDetail self {class Mapper} mapPoint ->
  86. (
  87.     -- Calculate which quadrant the point is in.
  88.     local quadrantX := ((mapPoint.x / self.quadrantWidth) as Integer) + 1
  89.     local quadrantY := ((mapPoint.y / self.quadrantHeight) as Integer) + 1
  90.     
  91.     -- Use the quadrant as an index into the detail maps.
  92.     local detailMap := self.detailMaps[quadrantX * 100 + quadrantY]
  93.     
  94.     -- Calculate detail map location, and add a push pin there.
  95.     local detailX := ((mod mapPoint.x self.quadrantWidth) * self.detailWidth) / self.quadrantWidth
  96.     local detailY := ((mod mapPoint.y self.quadrantHeight) * self.detailHeight) / self.quadrantHeight
  97.     local pushPin := new TwoDShape boundary:self.media["pushpin"] fill:blackBrush
  98.     translate pushPin.transform detailX detailY
  99.     
  100.     -- Create a TwoDMultipresenter for the detail map and the push pin.
  101.     local detail := new TwoDMultiPresenter boundary:detailMap.boundary
  102.     prepend detail detailMap
  103.     prepend detail pushPin
  104.     return detail
  105. )
  106.  
  107. method editObject self {class Mapper} button ->
  108. (
  109.     button.target.mapPresenter := getDetail self button.target.location
  110.  
  111.     -- If there is no detail map document, create one and add it to a palette window.
  112.     if (self.detailDocument = undefined) then
  113.     (
  114.         -- Note, Due to Win '95 bug, detailWidth and detailHeight 
  115.         -- had to be changed to multiple of 4.  Should be 365, 274.
  116.         local d := new MapDocument boundary:(new Rect x2:self.detailWidth y2:self.detailHeight) \
  117.             media:self.media target:button.target
  118.         self.detailDocument := d
  119.         local detailWin := new detailWindow parentDoc:self media:self.media \
  120.             boundary:(new Rect x2:self.detailWidth y2:self.detailHeight) \
  121.             name:"Car Detail" title:theTitleContainer centered:true
  122.         prepend detailWin d
  123.         show detailWin
  124.         
  125.     )
  126.     -- Otherwise, change the target of the existing detail document.
  127.     else
  128.     (
  129.         self.detailDocument.target := button.target
  130.         show self.detailDocument.presentedBy
  131.     )
  132.     goTo self.detailDocument 1
  133. )
  134.  
  135. -- Method addObject adds a map representation of an object to self.
  136. method addObject self {class Mapper} obj ->
  137. (
  138.     -- Create a map presenter for the specified object, and add it to the map.
  139.     local pin := self.media["pushpin"]
  140.     local rp := new TwoDShape boundary:pin fill:blackBrush
  141.     local pp := new TwoDShape boundary:pin fill:blackBrush
  142.     local mp := new PushButton releasedPresenter:rp pressedPresenter:pp
  143.     
  144.     -- Get mapPresenter's position, and prepend to the map.
  145.     mp.x := obj.location.x
  146.     mp.y := obj.location.y
  147.     mp.target := obj
  148.     mp.authorData := self
  149.     mp.activateAction := editObject
  150.     prepend self mp
  151. )
  152.  
  153. -- Method addManyObjects adds every member of a collection to self.
  154. method addManyObjects self {class Mapper} a ->
  155. (
  156.     for obj in a do addObject self obj
  157. )
  158.  
  159. -- Method getScale is used by tools to query the scale of the space.
  160. method getScale self {class Mapper} ->
  161. (
  162.     return #(#("Miles", 17))
  163. )
  164.  
  165. -->>>
  166. "Compiled mapper.sx"
  167.